package cn.edu.lzu.unitweb.listener;

import cn.edu.lzu.unitweb.config.ExaminerSessionDao;
import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;
import org.apache.shiro.session.mgt.eis.SessionDAO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.annotation.WebListener;

@Component
@WebListener
public class ExaminerListener implements SessionListener{
    @Resource
    private ExaminerSessionDao examinerSessionDao;


    //新建session
    @Override
    public synchronized void onStart(Session session) {
        System.out.println("有用户尝试登录");
        System.out.println("当前在线人数为:"+examinerSessionDao.getActiveSessions().size()+"人");
    }

    //删除session
    @Override
    public synchronized void onStop(Session session) {
        System.out.println("有用户退出");
        System.out.println("当前在线人数为:"+examinerSessionDao.getActiveSessions().size()+"人");
    }

    //session到期
    @Override
    public synchronized void onExpiration(Session session) {
        System.out.println("有session到期");
        System.out.println("当前在线人数为:"+examinerSessionDao.getActiveSessions().size()+"人");

    }
}
